# abbr -a mv mv -i
# abbr -a cp cp -i

function sudonew
	set a (echo $argv[1] |sed 's/\.sh$//')
	set a $a'.sh'
	echo '创建脚本'$a        
	sudo touch $a .
	sudo sh -c "echo '#!/bin/bash\n\nshelldir=\$(dirname \$(readlink -f \"\$0\"))\n\n' > "$a
	sudo chmod 755 $a
end


function groups 
    	cat /etc/group | awk -F : '
    	BEGIN{
        	printf "%-20s|%-8s|%-s\n\n","Group name","GID","Users";
    	}
    	{	
        	if($4=="")
            		printf "%-20s|%-8s|%-s\n",$1,$3,$1;
        	else 
            		printf "%-20s|%-8s|%-s\n",$1,$3,$4
    	}'
end 

function addpath
    	set PATH $argv[1]:$PATH
end

function conf
    	vim ~/.config/fish/config.fish
end


#--install /usr/bin/java java /JAVA_HOME/java 200
#--display java
#--remove java /JAVA_HOME/java

function select
    	sudo update-alternatives $argv
end

function database  
    	mycli -u lyf -h localhost -p 123 $argv[1]	
end


function islisten
    	set filter $argv[1]' \|Proto'
    	if test -n "$argv[2]"
		netstat -anp | grep -v 'unix\|UNIX\|RefCnt' | grep $filter |grep $argv[2]'\|Proto'
    	else
     		netstat -anp | grep -v 'unix\|UNIX\|RefCnt' | grep $filter |grep 'LISTEN\|Proto'
    	end	
end

function link
    	if test -n "$argv[2]"
    		sudo ln -s $PWD'/'$argv[1]   '/usr/bin/'$argv[2]	
	else
    		sudo ln -s $PWD'/'$argv[1]   '/usr/bin/'$argv[1]
	end	
end


function locate
        ls -l '/proc/'$argv[1]'/exe'
end


function start
         echo $argv | xargs nohup >/dev/null 2>&1 &
end


######gobal######gobal######gobal######gobal######gobal######gobal######gobal######gobal######gobal######gobal


# 打开多媒体资源
abbr -a see cmd /C start

# 打开windows路径
abbr -a cd wcd

function mv
        command mv -i $argv
end

function cp
        command cp -i $argv
end

# clear trash

function ct
     command rm -rf ~/.Trash
     mkdir ~/.Trash
end

function rm
        mv -i $argv ~/.Trash/
end

function mr
        mv -i ~/.Trash/$argv ./
end

function lt
        la ~/.Trash
end

#################

function wcd
    if test $argv
            cd ( w2l $argv )
    else
            cd
    end
end

function w2l
        echo $argv | sed -e "s#C:#/mnt/c#;s#\\\#\\/#g"
end
function l2w
        echo $argv | sed -e "s#/mnt/c#C:#"
end

function new
        set a (echo $argv[1] |sed 's/\.sh$//')
        set a $a'.sh'
        touch $a .
        echo -e "#!/bin/bash\n\nshelldir=\$(dirname \$(readlink -f \"\$0\"))\n\n" > $a
        chmod 755 $a
end

function conf
        vim /etc/fish/config.fish
end